package com.lx.config;

import com.alibaba.druid.pool.DruidDataSource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

import lombok.Data;

/**
 * 主数据源配置
 *
 * @author 段誉
 * @create 2019-04-12 14:57
 */
@Data
@Configuration
//@EnableConfigurationProperties(PrimaryDataBaseConfig.class)
// 前缀为primary.datasource.druid的配置信息
//@ConfigurationProperties(prefix = "primary.datasource.druid")
@MapperScan(basePackages = PrimaryDataBaseConfig.PACKAGE, sqlSessionFactoryRef = "primarySqlSessionFactory")
public class PrimaryDataBaseConfig {
  /**
   * dao层的包路径
   */
  public static final String PACKAGE = "com.lx.dao.primary";
  /**
   * mapper文件的相对路径
   */
  private static final String MAPPER_LOCATION = "classpath:mappers/primary/*.xml";
  private String filters;
  private String url;
  private String username;
  private String password;
  private String driverClassName;
  private int initialSize;
  private int minIdle;
  private int maxActive;
  private long maxWait;
  private long timeBetweenEvictionRunsMillis;
  private long minEvictableIdleTimeMillis;
  private String validationQuery;
  private boolean testWhileIdle;
  private boolean testOnBorrow;
  private boolean testOnReturn;
  private boolean poolPreparedStatements;
  private int maxPoolPreparedStatementPerConnectionSize;

  /**
   * 主数据源使用@Primary注解进行标识
   */
  @Primary
  @Bean(name = "primaryDataSource")
  public DataSource primaryDataSource() {
    DruidDataSource druid = new DruidDataSource();
    //监控统计拦截的filters
//    druid.setFilters();
    return druid;
  }
}
